<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增阀门设备数据')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-data-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">阀门ID：</label>
                <div class="col-sm-8">
                    <input name="valveId" id="valveId" class="form-control" minlength="4" maxlength="4"  type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">阀门型号：</label>
                <div class="col-sm-8">
                    <select name="typeId" class="form-control">
                        <option th:each="valve : ${valveList}" th:text="${valve['typeName']}" th:value="${valve['typeId']}" th:field="*{typeId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="installTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">安装地址：</label>
                <div class="col-sm-8">
                    <textarea name="installAddress" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">安装人：</label>
                <div class="col-sm-8">
                    <input name="installUser" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "module/valve/data"
        $("#form-data-add").validate({
            onkeyup: false,
            rules: {
                valveId: {
                    remote: {
                        url: prefix + "/checkValveDataCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "valveId": function() {
                                return $.common.trim($("#valveId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "valveId": {
                    remote: "阀门ID已存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-data-add').serialize());
            }
        }

        $("input[name='installTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>